import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:new_yuqib_app/yqbConfig/file_path.dart';
import 'package:new_yuqib_app/yqbConfig/storage_config.dart';
import 'package:new_yuqib_app/yqbConfig/yqb_base.dart';
import 'package:new_yuqib_app/yqbNetwork/api_metholds.dart';
import 'package:new_yuqib_app/yqbView/IndexView/view.dart';
import 'package:new_yuqib_app/yqbView/loginView/view.dart';
import 'package:new_yuqib_app/yqbWidget/xie_hit_widget.dart';

///首次展示页面
class YqbFirstPage extends StatefulWidget {
  const YqbFirstPage({super.key});

  @override
  State<YqbFirstPage> createState() => _YqbFirstPageState();
}

class _YqbFirstPageState extends State<YqbFirstPage> {
  ///判断是否登录
  void checkToken() {
    if (StorageConfig.token.isNotEmpty) {
      Get.off(
        const IndexView(),
        transition: Transition.fade,
        duration: const Duration(seconds: 1),
      );
    } else {
      Get.off(
        const LoginView(),
        transition: Transition.fade,
        duration: const Duration(seconds: 1),
      );
    }
  }

  //是否阅读协议内容
  void checkXieYi() async {
    if (StorageConfig.xieYi) {
      checkToken();
    } else {
      final res = await Get.bottomSheet<bool>(isDismissible: false, const XieYiContentView());
      if (res != null && res) {
        checkToken();
      }
    }
  }

  //初始化
  void init() async {
    ApiMethods.init().then((value) {
      Future.delayed(const Duration(seconds: 3), checkXieYi);
    });
  }

  @override
  void initState() {
    super.initState();
    init();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        children: [
          SizedBox.fromSize(size: const Size.fromHeight(220)),
          Container(
            width: 74,
            height: 74,
            decoration: BoxDecoration(
              image: const DecorationImage(
                image: AssetImage(FilePath.iconPath),
                fit: BoxFit.fill,
              ),
              borderRadius: BorderRadius.circular(99),
            ),
          ),
          const SizedBox(height: 16),
          const Text(
            appName,
            style: TextStyle(color: Colors.black, fontSize: 20),
          ),
        ],
      ),
    );
  }
}
